Mini Project Title: GDP per Capita and Life Expectancy between Canada and Hong Kong from 1952 to 2007¶

Chuen Kei Ho 101410183 & Ka Tsun Chan 101420274¶

Connected Scatterplots - In the plot below, we show the "trajectory" of Canada Vs Hong Kong through a space defined by GDP per Capita and Life Expectancy¶

In [25]:
##Credit to https://plotly.com/python/line-charts/

# #px.scatter(x=[1, 2, 3], y=[1, 2, 3])
df = px.data.gapminder().query("country in ['Canada', 'Hong Kong, China']")

fig = px.line(df, x="lifeExp", y="GDP Per Capita", color="country", text="year")
fig.update_traces(textposition="bottom right")
fig.show()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[25], line 6
      1 ##Credit to https://plotly.com/python/line-charts/
      2 
      3 # #px.scatter(x=[1, 2, 3], y=[1, 2, 3])
      4 df = px.data.gapminder().query("country in ['Canada', 'Hong Kong, China']")
----> 6 fig = px.line(df, x="lifeExp", y="GDP Per Capita", color="country", text="year")
      7 fig.update_traces(textposition="bottom right")
      8 fig.show()

File ~/opt/anaconda3/envs/webpage/lib/python3.11/site-packages/plotly/express/_chart_types.py:264, in line(data_frame, x, y, line_group, color, line_dash, symbol, hover_name, hover_data, custom_data, text, facet_row, facet_col, facet_col_wrap, facet_row_spacing, facet_col_spacing, error_x, error_x_minus, error_y, error_y_minus, animation_frame, animation_group, category_orders, labels, orientation, color_discrete_sequence, color_discrete_map, line_dash_sequence, line_dash_map, symbol_sequence, symbol_map, markers, log_x, log_y, range_x, range_y, line_shape, render_mode, title, template, width, height)
    216 def line(
    217     data_frame=None,
    218     x=None,
   (...)
    258     height=None,
    259 ) -> go.Figure:
    260     """
    261     In a 2D line plot, each row of `data_frame` is represented as vertex of
    262     a polyline mark in 2D space.
    263     """
--> 264     return make_figure(args=locals(), constructor=go.Scatter)

File ~/opt/anaconda3/envs/webpage/lib/python3.11/site-packages/plotly/express/_core.py:1991, in make_figure(args, constructor, trace_patch, layout_patch)
   1988 layout_patch = layout_patch or {}
   1989 apply_default_cascade(args)
-> 1991 args = build_dataframe(args, constructor)
   1992 if constructor in [go.Treemap, go.Sunburst, go.Icicle] and args["path"] is not None:
   1993     args = process_dataframe_hierarchy(args)

File ~/opt/anaconda3/envs/webpage/lib/python3.11/site-packages/plotly/express/_core.py:1406, in build_dataframe(args, constructor)
   1403     args["color"] = None
   1404 # now that things have been prepped, we do the systematic rewriting of `args`
-> 1406 df_output, wide_id_vars = process_args_into_dataframe(
   1407     args, wide_mode, var_name, value_name
   1408 )
   1410 # now that `df_output` exists and `args` contains only references, we complete
   1411 # the special-case and wide-mode handling by further rewriting args and/or mutating
   1412 # df_output
   1414 count_name = _escape_col_name(df_output, "count", [var_name, value_name])

File ~/opt/anaconda3/envs/webpage/lib/python3.11/site-packages/plotly/express/_core.py:1208, in process_args_into_dataframe(args, wide_mode, var_name, value_name)
   1206         if argument == "index":
   1207             err_msg += "\n To use the index, pass it in directly as `df.index`."
-> 1208         raise ValueError(err_msg)
   1209 elif length and len(df_input[argument]) != length:
   1210     raise ValueError(
   1211         "All arguments should have the same length. "
   1212         "The length of column argument `df[%s]` is %d, whereas the "
   (...)
   1219         )
   1220     )

ValueError: Value of 'y' is not the name of a column in 'data_frame'. Expected one of ['country', 'continent', 'year', 'lifeExp', 'pop', 'gdpPercap', 'iso_alpha', 'iso_num'] but received: GDP Per Capita

An Image¶

¶

To describe the trajectory of Canada and Hong Kong in a space defined by GDP per capita and life expectancy over the past 60 years, we need to look at how these two countries have fared over time.

In the 1960s, both Canada and Hong Kong had similar life expectancies, but Canada had a higher GDP per capita. Over the following decades, Canada continued to grow economically while also experiencing gains in life expectancy. By the 1980s, Canada had become one of the wealthiest nations in the world, with a high standard of living and a life expectancy of over 75 years.

Hong Kong, on the other hand, had a different trajectory. While its GDP per capita increased over time, its gains in life expectancy were even more impressive. By the 1990s, Hong Kong's life expectancy had surpassed that of Canada, despite having a lower GDP per capita. This can be attributed to Hong Kong's focus on public health initiatives and access to healthcare.

In the early 2000s, both countries continued to experience steady growth in both GDP per capita and life expectancy. However, in recent years, Hong Kong has faced political and economic challenges that have impacted its trajectory. Despite this, it still has a higher life expectancy than Canada, although Canada still has a higher GDP per capita.

Overall, while Canada and Hong Kong have taken different paths over the past 60 years, they both have seen significant improvements in their economies and quality of life. Despite some recent setbacks, both countries remain strong players on the world stage.

[Prepared by Chat GPT]

¶

reference and credit to plotly.com

In [ ]: